import { createRouter, createWebHistory } from 'vue-router'
import { userStatus } from '@/stores/userStatus'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'root',
      component: () => import('@/views/GameView.vue')
    },
    {
      path: '/history',
      name: 'history',
      component: () => import('@/views/HistoryView.vue'),
      beforeEnter: (to, from, next) => {
        const userStore = userStatus()
        if (userStore.hasLogin) {
          next()
        }
        else {
          router.push('/login')
        }
        
      }
    },
    {
      path: '/login',
      name: 'userlogin',
      component: () => import('@/views/LoginView.vue')
    }
  ]
})

export default router
